import { ref } from 'vue'
import { useIntersectionObserver } from '@vueuse/core'

export const useLazyLoad = (apiFn: () => void) => {
  const target = ref(null)

  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      // 发请求执行的函数
      apiFn()

      stop()
    }
  })

  return { target }
}
